<!DOCTYPE html>
<html lang="zh">
	<head>
		<meta charset="UTF-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<title>随机数</title>
	</head>
	<body>
		<button id="testClick">点击我生成随机数</button>
		<div style="width: 200px;height: 50px;background: red;color: white;" id="result"></div>

		<script>
			document.getElementById('testClick').addEventListener('click', e => {
				document.getElementById('result').innerHTML = getRandom(-50, 100);
			})

			/**
			 * @param {Object} min
			 * @param {Object} max
			 * 如果把Math.floor缓存parseInt的区别是  Math.floor如果最小值是负数的时候是向x轴左边取整，而parseInt是向0取整的
			 */
			function getRandom(min, max) {
				return Math.floor(Math.random() * (max - min) + min)
			}
		</script>
	</body>
</html>
